﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SMS.Core.Controller;
using PureMVC.Patterns;
using SMS.Core.View.Component;

namespace SMS.Core
{
    public class ApplicationFacade : Facade
    {
        #region Constructors

        /// <summary>
        /// Inheritable Singleton constructor for the <c>ApplicationFacade</c>
        /// </summary>
        protected ApplicationFacade() { }

        static ApplicationFacade()
        {
            m_instance = new ApplicationFacade();
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Sends a startup notification to the <c>ApplicationController</c> to kickstart the application.
        /// Also displays the <c>LoginForm</c> which is the starting point of the application.
        /// </summary>
        /// <param name="start">The object to be displayed upon a successful application startup.</param>
        public void Startup(object start)
        {
            SendNotification(ApplicationConstants.STARTUP, start);
            (start as Form).ShowDialog(new MainForm());
            (start as Form).Dispose();
            // After logging in, show the Main Form;
            Application.Run(new MainForm());
            return;
        }

        #endregion

        #region Accessors

        public static new ApplicationFacade Instance
        {
            get
            {
                return m_instance as ApplicationFacade;
            }
        }

        #endregion

        #region Private & Internal Methods

        protected override void InitializeFacade()
        {
            base.InitializeFacade();
        }

        protected override void InitializeController()
        {
            if (m_controller != null) 
                return;
            m_controller = ApplicationController.Instance;
        }

        protected override void InitializeModel()
        {
            base.InitializeModel();
        }

        protected override void InitializeView()
        {
            base.InitializeView();
        }

        #endregion
    }
}
